package fun.liuyu2783.txmessage.goods.mq;

import fun.liuyu2783.txmessage.goods.dto.Trade;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.common.consumer.ConsumeFromWhere;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener;
import org.springframework.stereotype.Service;

@Slf4j
@Service
@RocketMQMessageListener(topic = "ORDER_TOPIC", selectorExpression = "create", consumerGroup = "Goods_Order_Create_Group")
public class OrderCreateConsumer implements RocketMQListener<Trade>, RocketMQPushConsumerLifecycleListener {

    @Override
    public void onMessage(Trade trade) {
        log.info("接收到订单创建消息：{}", trade);
    }

    @Override
    public void prepareStart(DefaultMQPushConsumer defaultMQPushConsumer) {
        defaultMQPushConsumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_LAST_OFFSET);
    }

}
